﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace wpftest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private bool isContinue = true;
        public MainWindow()
        {
            InitializeComponent();
            Closed += MainWindow_Closed;
            
        }

        void MainWindow_Closed(object sender, EventArgs e)
        {
            isContinue = false;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            textbox1.Text = "Hello WPF";
        }

        private void ThreadHandler()
        {
            while (isContinue)
            {
                Dispatcher.Invoke(new Action(() => textbox1.Text = DateTime.Now.ToString()));
                Thread.Sleep(3000);
            }
        }

        private void MainWindow_load(object sender, RoutedEventArgs e)
        {
            Thread t = new Thread(new ThreadStart(ThreadHandler));
            t.IsBackground = false;
            t.Start();
        }
    }
}
